package com.obtk.property.controller;

import com.github.pagehelper.Page;
import com.obtk.property.common.MessageRepair;
import com.obtk.property.common.PageResult;
import com.obtk.property.common.Result;
import com.obtk.property.common.StatusCode;
import com.obtk.property.pojo.Repair;
import com.obtk.property.service.RepairService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/repair")
public class RepairController {

    private final RepairService repairService;


    public RepairController(RepairService repairService) {
        this.repairService = repairService;
    }

    @RequestMapping("/find")
    public Result find(){
        List<Repair> all= repairService.findAll();
        return new Result(true,200,"请求成功",all);
    }
    @RequestMapping("/search")
    public PageResult search(@RequestBody Map searchMap){
        Page<Repair> page = repairService.search(searchMap);
        return new PageResult(true, StatusCode.OK, MessageRepair.Repair_SEARCH_SUCCESS,page.getResult(),page.getTotal());
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Repair repair){
        Boolean add = repairService.add(repair);
        return new Result(true,StatusCode.OK, MessageRepair.Repair_ADD_SUCCESS);
    }

    @RequestMapping("/findById")
    public Result findById(Integer repairId){
        Repair repair = repairService.findById(repairId);
        return new Result(true,StatusCode.OK, MessageRepair.Repair_FIND_BY_ID_SUCCESS,repair);
    }
    @RequestMapping("/update")
    public Result update(@RequestBody Repair repair){
        Boolean add = repairService.update(repair);
        return new Result(true,StatusCode.OK, MessageRepair.Repair_UPDATE_SUCCESS);
    }

    @RequestMapping("/del")
    public Result del(@RequestBody List<Integer> ids){
        Boolean flag = repairService.del(ids);
        return new Result(true,StatusCode.OK, MessageRepair.Repair_DELETE_SUCCESS);
    }

}
